package net.zui.entity;

import java.awt.Graphics2D;
import java.awt.Image;

import net.zui.comp.ZBase;
import net.zui.util.UComm;

public abstract class ZImage {
	protected Image image;

	public ZImage(Image image) {
		this.image=image;
	}
	
	public abstract void draw(Graphics2D g,ZBase base);
	
	/**
	  * 图像从左上角绘制
	 * <br /><br />
	 * <b>作者:</b>张天文 <br />
	 * <b>日期:</b>2021年5月17日上午11:12:17<br />
	 * @date
	 */
	public static class Default extends ZImage{

		public Default(Image image) {
			super(image);
		}
		
		@Override
		public void draw(Graphics2D g, ZBase base) {
			g.drawImage(image, 0, 0, Math.min(image.getWidth(null), base.getWidth()), Math.min(image.getHeight(null), base.getHeight()),null);			
		}
	}
	
	/**
	  * 图像绘制在ZBase中心
	 * <br /><br />
	 * <b>作者:</b>张天文 <br />
	 * <b>日期:</b>2021年5月25日下午2:23:09<br />
	 * @date
	 */
	public static class Center extends ZImage{
		public Center(Image image) {
			super(image);
		}

		@Override
		public void draw(Graphics2D g, ZBase base) {
			int width = image.getWidth(null);
			int height=image.getHeight(null);
			int cwidth=base.getOuterWidth();
			int cheight=base.getOuterHeight();
			int x,y,mwidth,mheight;
			x=width>cwidth?(width-cwidth)/2:(cwidth-width)/2;
			y=height>cheight?(height-cheight)/2:(cheight-height)/2;
			mwidth=width>cwidth?cwidth:width;
			mheight=height>cheight?cheight:height;
			UComm.info(this.getClass(), x," ",y," ",mwidth," ",mheight);
			g.drawImage(image,0,0,cwidth,cheight, x, y, x+mwidth, y+mheight,null);
		}
	}
	
	/**
	  * 图像充满ZBase
	 * <br /><br />
	 * <b>作者:</b>张天文 <br />
	 * <b>日期:</b>2021年5月25日下午2:24:08<br />
	 * @date
	 */
	public static class Fill extends ZImage{
		public Fill(Image image) {
			super(image);
		}

		@Override
		public void draw(Graphics2D g, ZBase base) {
			g.drawImage(image, 0, 0, base.getOuterWidth(), base.getOuterWidth(), null);
		}
	}
	
	public Image getImage() {
		return image;
	}

	public void setImage(Image image) {
		this.image = image;
	}
}
